using UnityEngine;
using System.Collections;

public class MovingPlatform : MonoBehaviour
{
    bool sens;

    public float m_MovementTime;
    public float m_StartMovementTime;

    public Vector3 m_StartPosition;
    public Vector3 m_EndPosition;

    public Vector3 m_Start;
    public Vector3 m_End;

    Transform m_Solid;

	// Use this for initialization
	void Start () 
    {
        sens = true;
        m_StartMovementTime = Time.time;

        m_StartPosition = transform.FindChild("Start").transform.position;
        m_EndPosition = transform.FindChild("End").transform.position;
        m_Solid = transform.FindChild("Solid").transform;

        m_End = m_EndPosition;
        m_Start = m_StartPosition;

	}
	
	// Update is called once per frame
	void Update () 
    {
        float val = m_MovementTime;

        Debug.Log(Time.time + " " + m_StartMovementTime);
        Debug.Log("movement "+m_StartMovementTime + m_MovementTime);

        float val2=(Time.time-m_StartMovementTime)/val;

        if(val2>1.0f)
        {
            val2=1.0f;
        }
        Debug.Log(val2);
        m_Solid.position= Vector3.Lerp(m_Start, m_End, val2);
        

        if (Time.time > (m_StartMovementTime + m_MovementTime))
        {
            Debug.Log("Lol?");
            if (sens)       // De start vers End
            {
                m_Start = m_EndPosition;
                m_End = m_StartPosition;
                m_StartMovementTime = Time.time;
                sens = false;
            }
            else
            {
                sens=true;
                m_Start = m_StartPosition;
                m_End = m_EndPosition;
                m_StartMovementTime = Time.time;
            }
        }
	}
}
